
//LD293
const int moterLogic1a = 2;
const int moterLogic1b = 3;
const int moterLogic1e = 9;
const int moterLogic2a = 4;
const int moterLogic2b = 5;
const int moterLogic2e = 10;

void motorSetup(){
  pinMode(moterLogic1a, OUTPUT);
  pinMode(moterLogic1b, OUTPUT);
  pinMode(moterLogic1e, OUTPUT);
  pinMode(moterLogic2a, OUTPUT);
  pinMode(moterLogic2b, OUTPUT);
  pinMode(moterLogic2e, OUTPUT);
}

void forward(int speed){
  setMotorLogic(HIGH, LOW, HIGH, LOW);
  setSpeed(speed);
}

void backward(int speed){
  setMotorLogic(LOW, HIGH, LOW, HIGH);
  setSpeed(speed);
}

void right(int speed){
  setMotorLogic(HIGH, LOW, LOW, LOW);
  setSpeed(speed);
}

void left(int speed){
  setMotorLogic(LOW, LOW, HIGH, LOW);
  setSpeed(speed);
}

void stopp() { 
  setSpeed(0);
  delay(500);
}

void setMotorLogic(byte m11, byte m12, byte m21, byte m22){
  set(moterLogic1a,m11);
  set(moterLogic1b,m12);
  set(moterLogic2a,m21);
  set(moterLogic2b,m22);
}

void setSpeed(int speed) {
  analogWrite(moterLogic1e, speed);
  analogWrite(moterLogic2e, speed);
}
